#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;
using vegl = vector < pair < int, ll > >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e5 + 10;

int n, Q, A;
veg G[N];

namespace L {
	const int N = 3e5 + 10;
	const int K = 21;
	int stk[N], dep[N], tot, dfn[N], R[N], mn[K + 1][N], lg[N], pw[K + 10];
	int tdep[N];
	void dfs(int x, int p) {
		stk[dfn[x] = R[x] = ++tot] = x; dep[x] = dep[p] + 1; int y, w;
		for(auto v : G[x]) {
			tie(y, w) = v; if(y == p) continue;
			tdep[y] = tdep[x] + w; dfs(y, x); stk[R[x] = ++tot] = x; 
		}
	}
	inline int tmn(int x, int y) { return dep[x] < dep[y] ? x : y; }
	inline int LCA(int x, int y) { if(dfn[x] > dfn[y]) swap(x, y); x = dfn[x]; y = R[y]; int k = lg[y - x + 1]; return tmn(mn[k][x], mn[k][y - pw[k] + 1]); }
	inline int dis(int x, int y) { return tdep[x] + tdep[y] - tdep[LCA(x, y)] * 2; }
	void build() {
		dfs(1, 0); rep(i, 2, tot) lg[i] = lg[i >> 1] + 1;
		pw[0] = 1; rep(i, 1, K) pw[i] = pw[i - 1] * 2;
		rep(i, 1, tot) mn[0][i] = stk[i];
		rep(i, 1, K) rep(j, 1, tot - pw[i] + 1) mn[i][j] = tmn(mn[i - 1][j], mn[i - 1][j + pw[i - 1]]);
	}
}

namespace T {
	int fa[N], siz[N], son[N], rt;
	bool vis[N];
	struct Delpri {
		priority_queue < int > q1, q2;
		void ins(int x) { q1.ep(x); }
		void erase(int x) { q2.ep(x); }
		void resize() { while(q1.size() && q2.size() && q1.top() == q2.top()) q1.pop(), q2.pop(); }
		int top() { resize(); return q1.top(); }
		int size() { return int(q1.size()) - int(q2.size()); }
		int calc() {
			if(size() < 1) return -1e9;
			int res = top(), tres = 0; erase(res);
			if(size() == 0) return ins(res), res;
			tres = top() + res; ins(res); /*cerr << tres << endl;*/ return tres;
		}
	} val[N], vfa[N], global;
	void gsz(int x, int p) {
		siz[x] = 1; son[x] = 0; for(auto v : G[x]) if(!vis[v.fi] && v.fi ^ p) gsz(v.fi, x), siz[x] += siz[v.fi], chkmax(son[x], siz[v.fi]);
	}
	void grt(int x, int p, int tsz) {
		for(auto v : G[x]) if(!vis[v.fi] && v.fi ^ p) grt(v.fi, x, tsz); chkmax(son[x], tsz - siz[x]); if(rt == 0 || son[x] < son[rt]) rt = x;
	}
	int divide(int x) {
		gsz(x, 0); rt = 0; grt(x, 0, siz[x]); x = rt; vis[x] = true;
		for(auto v : G[x])
			if(!vis[v.fi]) fa[divide(v.fi)] = x;
		return x;
	}
	int tres[N];
	void tera(int x) {
		if(fa[x]) {
			global.erase(tres[fa[x]]);
			vfa[fa[x]].erase(val[x].top());
		}
	}
	void tnow(int x) {
		if(fa[x]) {
			vfa[fa[x]].ins(val[x].top());
			global.ins(tres[fa[x]] = vfa[fa[x]].calc());
		}
	}
	int getans() { return global.top(); }
	void upd(int tx) {
		int u = tx; global.erase(tres[u]); vfa[u].ins(0); global.ins(tres[u] = vfa[u].calc());
		while(fa[u]) tera(u), val[u].ins(L :: dis(tx, fa[u])), tnow(u), u = fa[u];
	}
	void del(int tx) {
		int u = tx; global.erase(tres[u]); vfa[u].erase(0); global.ins(tres[u] = vfa[u].calc());
		while(fa[u]) tera(u), val[u].erase(L :: dis(tx, fa[u])), tnow(u), u = fa[u];
	}
	void build() {
		divide(1); rep(i, 1, n) val[i].ins(-1e9), vfa[fa[i]].ins(val[i].top());
		rep(i, 1, n) global.ins(tres[i] = vfa[i].calc());
		rep(i, 1, n) upd(i);
	}
}

int stu[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in;
	rep(i, 2, n) { int u = in, v = in, w = in; G[u].eb(v, w), G[v].eb(u, w); }
	L :: build(); T :: build();
	Q = in; int cntwhite = n;
	while(Q--) {
		char op = getchar(); while(!isalpha(op)) op = getchar();
		if(op == 'C') {
			int x = in;
			if(stu[x] == 0) cntwhite--, T :: del(x);
			else cntwhite++, T :: upd(x);
			stu[x] ^= 1;
		} else {
			if(cntwhite == 0) puts("They have disappeared.");
			else if(cntwhite == 1) puts("0");
			else printf("%d\n", max(0, T :: getans()));
		}
	}
	return 0;
}
